var AjaxMethod = require("../getAjax.js"); 
var ajax = new  AjaxMethod;
export default{
    state:{
    	data_cartdata:'',
    	data_cartlist:[],
    	data_delGood:{},
    },
    mutations:{
    	//购物车
    	set_cartlist:function(state,{list}){
    		state.data_cartlist = list;
    	},
    	//购物车 所有信息
    	set_cardata:function(state,{list}){
    		state.data_cartdata = list;
    	},
    	//购物车删除
    	set_delGood:function(state,{list}){
    		state.data_delGood = list;
    	}
    },
    actions:{
    	//购物车
    	get_cartlist:function(context){
    		var Atype = "post", 
                //Aurl = baseUrl+'/products/'+_goodId+'.html',
                Aurl = baseUrl+"/carts/list.html?REQUEST_JSON={visitChannel:2,pageIndex:1,CURRENCY:'CNY',commandInfo:{}}";
            ajax.getJson(Atype,Aurl,function(res){
                //console.log(res)
                //if(){}
                context.commit("set_cardata",{list:res.data.cartInfo})
                context.commit("set_cartlist",{list:res.data.cartInfo.cartListVOs[0].cartList});
            },function(err){
                console.log(err)
            },function(){
                //context.state.Ajaxing = true; // 加载中显示...
            })
    	},
    	//购物车删除   
    	get_delGood:function(context,vm){
    		console.log(context.state.data_delGood)
    		var _obj = context.state.data_delGood;
    		var _arr = [];
    		var _str = '';
    		for(var o in _obj){
    			_str = '{'+o+':'+_obj[o]+'}'
       		}
    		console.log(_str)
    		var Atype = "post", 
                //Aurl = baseUrl+'/products/'+_goodId+'.html',
                Aurl = baseUrl+"/carts/deleteCartById.html?REQUEST_JSON={visitChannel:2,pageIndex:1,CURRENCY:'CNY',commandInfo:{idList:["+_str+"]}}";
            ajax.getJson(Atype,Aurl,function(res){
                console.log(res)
                //if(){}
                context.commit("set_delGood",{list:res.data})
                //context.commit("set_cartlist",{list:res.data.cartInfo.cartListVOs[0].cartList});
            },function(err){
                console.log(err)
            },function(){
                //context.state.Ajaxing = true; // 加载中显示...
            })
    	},
    },

}